package com.flipdf2.serialize.ppml.element;

import java.net.URI;

import org.jdom.Element;
import org.jdom.Namespace;

import com.flipdf2.serialize.ppml.PPMLConstant;
import com.flipdf2.serialize.ppml.PPMLException;

public class PPMLExternalData {
	public static final String NAME = "EXTERNAL_DATA";
	
	private URI src;
	private String checksum;
	private String checksumType = "MD5";
	private String sourceUsage = PPMLConstant.PPMLUsage.UNKNOW;

	public Element toXML(Namespace defaultNamespace) {
		Element root = null;
		if (defaultNamespace != null) {
			root = new Element(NAME, defaultNamespace);
		} else {
			root = new Element(NAME);	
		}
		
		if (src != null) 
			root.setAttribute("Src", src.toString());
		if (checksum != null) 
			root.setAttribute("Checksum", checksum);
		if (checksumType != null) 
			root.setAttribute("ChecksumType", checksumType);
		if (sourceUsage != null) 
			root.setAttribute("SourceUsage", sourceUsage);
		
		return root;
	}
	
	public void check() throws PPMLException {
		if (src == null) {
			throw PPMLException.getInstance(PPMLException.REQUIRED_ATTRIBUTE_LOST, "Src");
		}
	}

	public String getChecksum() {
		return checksum;
	}


	public void setChecksum(String checksum) {
		this.checksum = checksum;
	}


	public String getChecksumType() {
		return checksumType;
	}


	public void setChecksumType(String checksumType) {
		this.checksumType = checksumType;
	}


	public String getSourceUsage() {
		return sourceUsage;
	}


	public void setSourceUsage(String sourceUsage) {
		this.sourceUsage = sourceUsage;
	}


	public URI getSrc() {
		return src;
	}


	public void setSrc(URI src) {
		this.src = src;
	}
}
